﻿class com.dinmax.flash.central.draw.DepthManager {
	
	//private var depths:Collection; // de numbers
	private var clips:Array; // de MovieClips
	
	private static var instance:DepthManager;
		
	public static function getActive():DepthManager {
		return instance;
	}
	
	public static function newInstance():Void {
		instance = new DepthManager();
	}
	
	function DepthManager(){
		clips = new Array();
	};
	
	public function registerClip(clip:MovieClip):Void {
		clips.push(clip);
	};
	
	public function toFront(clip:MovieClip):Void {
		clip.swapDepths(getMaxDepth().getDepth() + 1);
	};
	
	public function toBack(clip:MovieClip):Void {
		clip.swapDepths(getMaxDepth().getDepth() - 1);
	};
	
	public function stepFoward(clip:MovieClip):Void {
		
	};
	
	public function stepBackward(clip:MovieClip):Void {

	};
	
	private function getMaxDepth():MovieClip {
		var clip:MovieClip;
		var nDepth:Number = Number.MIN_VALUE;
		for(var i:Number=0; i < clips.length; i++){
			if(clips[i].getDepth() > nDepth) {
				nDepth = clips[i].getDepth();
				clip = clips[i];
			}
		};
		return clip;
	};
	
	private function getMinDepth():MovieClip {
		var clip:MovieClip;
		var nDepth:Number = Number.MAX_VALUE;
		for(var i:Number=0; i < clips.length; i++){
			if(clips[i].getDepth() < nDepth) {
				nDepth = clips[i].getDepth();
				clip = clips[i];
			}
		};
		return clip;
	};
	
	private function getPrevDepth():MovieClip {
		return undefined;
	};
	
	private function getNextDepth():MovieClip {
		return undefined;
	};
	
}// fin de clase